import React from 'react';
import { View, Image, Clipboard, TextInput } from 'react-native';
import { Lt, Color, Label, Jpp, Jx, Button, Dialog, Images } from "../_utils";
import { eApp } from './_home';

function toCentent(data){
    let context = data.goodName;
    const app = eApp.idxs[data.appIdx];
    const isTBTM = app == eApp.TB || app == eApp.TM;
    
    if(data.zk_money){
        context += 
        "\n【在售价】" + data.price + 
        "\n【优惠券】" + data.zk_money;
    }
    context += "\n【下单价】" + data.zk_price;
    if(isTBTM && data.tkLink){
        context += "\n【淘口令】" + data.tkLink;
    }else {
        context += "\n【链接】" + (data.uland_url || data.url);
    }
    return context;
}

// 商品界面 分享文案
export class ShareContent extends React.PureComponent{
    constructor(props){
        super(props);
        const { data } = this.props;
        this.state = {
            content : (data.titile || data.content) ? ((data.titile || "") + "\n" + (data.content || "")) : toCentent(data),
        }
        this.onChangeText = this.onChangeText.bind(this);
        this.onCopy = this.onCopy.bind(this);
    }
    onChangeText(content){
        this.setState({content})
    }
    onCopy(){
        Clipboard.setString(this.state.content);
        Dialog.toast("文案已复制")
    }
    render(){
        return <View>
            <View style={{flexDirection:"row", margin:Lt.margin, justifyContent:"space-between", alignItems:"center"}}>
                <Label style={{fontSize:Lt.c18, color:Color.c3, }}>分享文案</Label>
                <Button.Border onPress={this.onCopy} title={"复制文案"} style={{borderWidth:0, fontSize:Lt.c16}}/>
            </View>
            <TextInput
                style={{marginHorizontal:Lt.margin, width:Jpp.width-Lt.margin*2, height:200, color:Color.c6, fontSize:Lt.c16}}
                underlineColorAndroid={Color.transparent}
                onChangeText={this.onChangeText}
                defaultValue={this.state.content}
                multiline={true}
            />
        </View>;
    }
}